package com.csx.micrometer.demo.consumer.controller;

import com.csx.micrometer.demo.consumer.client.DemoProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cuisongxu
 * @date 2022/12/6 14:27
 */
@RestController
@RequestMapping("/consumer/feign")
public class DemoConsumerFeignController {

    @Autowired
    private DemoProviderClient feignProviderClient;

    /**
     * 关于feign的一些指标，可以通过 引入 feign-micrometer 包来实现
     */
    @GetMapping("/testFeign")
    public String testFeign(@RequestParam("code") Integer code) {
        String feignUsername = feignProviderClient.getUserName(code);
        return "test feign " + feignUsername;
    }

    /**
     * 测试随机性运行时异常
     * @return
     */
    @GetMapping("/testRandomError")
    String testRandomError() {
        String result = feignProviderClient.testRandomError();
        return "consumer testRandomError " + result;
    }

    /**
     * 测试超时异常
     * @return
     */
    @GetMapping("/testTimeout")
    String testTimeout() {
        String result = feignProviderClient.testTimeout();
        return "consumer testTimeout " + result;
    }

    /**
     * 测试不存在的接口异常
     * @return
     */
    @GetMapping("/testNotExistEndpoint")
    String testNotExistEndpoint() {
        String result = feignProviderClient.testNotExistEndpoint();
        return "consumer testNotExistEndpoint " + result;
    }

}
